package com.cjj.join;

class ThreadJoin extends Thread{
    @Override
    public void run() {
        for(int i = 0; i < 40; i++){
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(getName() + "----" + i);
        }
    }
}

/**
 * @ClassName JoinTest
 * @Date 2021/07/18 18:33:26
 * @Created by ccc-j
 * @email ccc-ju@outlook.com
 */
public class JoinTest {

    public static void main(String[] args) {
        ThreadJoin join1 = new ThreadJoin();
        ThreadJoin join2 = new ThreadJoin();
        join1.start();
        try {
            join1.join(); // 让其它线程等待，只有自己当前线程执行完毕才会释放资源
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        join2.start();
        for(int i = 0; i < 40; i++){
            try {
                join2.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("main----" + i);
        }
    }

}
